<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.11.5" />
<title>pyboy.plugins.base_plugin API documentation</title>
<meta name="description" content="" />
<link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
<link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
<style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:0.8em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script async src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_CHTML'></script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>pyboy.plugins.base_plugin</code></h1>
</header>
<section id="section-intro">
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">#
# License: See LICENSE.md file
# GitHub: https://github.com/Baekalfen/PyBoy
#

__pdoc__ = {
    &#34;PyBoyPlugin&#34;: False,
    &#34;PyBoyWindowPlugin&#34;: False,
    &#34;PyBoyGameWrapper.post_tick&#34;: False,
    &#34;PyBoyGameWrapper.enabled&#34;: False,
    &#34;PyBoyGameWrapper.argv&#34;: False,
}

import io
import random
import time
from array import array

import numpy as np

import pyboy
from pyboy.api.constants import SPRITES, TILES_CGB
from pyboy.core.lcd import CGBRenderer
from pyboy import utils

logger = pyboy.logging.get_logger(__name__)

ROWS, COLS = 144, 160


class PyBoyPlugin:
    argv = []

    def __init__(self, pyboy, mb, pyboy_argv):
        self.cgb = mb.cgb
        self.pyboy = pyboy
        self.mb = mb
        self.pyboy_argv = pyboy_argv
        self.renderer = self.mb.lcd.renderer
        self.is_cgb_renderer = isinstance(self.mb.lcd.renderer, CGBRenderer)
        if self.is_cgb_renderer:
            self.cgb_renderer = self.mb.lcd.renderer

    def handle_events(self, events):
        return events

    def post_tick(self):
        pass

    def window_title(self):
        return &#34;&#34;

    def stop(self):
        pass

    def enabled(self):
        return True


class PyBoyWindowPlugin(PyBoyPlugin):
    def __init__(self, pyboy, mb, pyboy_argv, *args, **kwargs):
        super().__init__(pyboy, mb, pyboy_argv, *args, **kwargs)

        self._ftime = time.perf_counter_ns()
        self.sound_support = False

        if not self.enabled():
            return

        scale = pyboy_argv.get(&#34;scale&#34;)
        self.scale = scale
        logger.debug(&#34;%s initialization&#34; % self.__class__.__name__)

        self._scaledresolution = (scale * COLS, scale * ROWS)
        logger.debug(&#34;Scale: x%d (%d, %d)&#34;, self.scale, self._scaledresolution[0], self._scaledresolution[1])

        self.enable_title = True
        if not utils.cython_compiled:
            self.renderer = mb.lcd.renderer
        self.sound = self.mb.sound

    def frame_limiter(self, speed):
        self._ftime += int((1.0 / (60.0 * speed)) * 1_000_000_000)
        now = time.perf_counter_ns()
        if speed &gt; 0 and self._ftime &gt; now:
            delay = (self._ftime - now) // 1_000_000
            time.sleep(delay / 1000)
        else:
            self._ftime = now
        return True

    def paused(self, pause):
        pass

    def set_title(self, title):
        pass


class PyBoyGameWrapper(PyBoyPlugin):
    &#34;&#34;&#34;
    This is the base-class for the game-wrappers. It provides some generic game-wrapping functionality, like `game_area`
    , which shows both sprites and tiles on the screen as a simple matrix.
    &#34;&#34;&#34;

    cartridge_title = None

    mapping_one_to_one = np.arange(TILES_CGB, dtype=np.uint8)
    &#34;&#34;&#34;
    Example mapping of 1:1
    &#34;&#34;&#34;

    def __init__(self, *args, game_area_section=(0, 0, 32, 32), game_area_follow_scxy=False, **kwargs):
        super().__init__(*args, **kwargs)
        if not utils.cython_compiled:
            self.tilemap_background = self.pyboy.tilemap_background
            self.tilemap_window = self.pyboy.tilemap_window
        self.tilemap_use_background = True
        self.mapping = np.arange(TILES_CGB, dtype=np.uint32)
        self.sprite_offset = 0
        self.game_has_started = False
        self._tile_cache_invalid = True
        self._sprite_cache_invalid = True

        self.shape = None
        &#34;&#34;&#34;
        The shape of the game area. This can be modified with `pyboy.PyBoy.game_area_dimensions`.

        Example:
        ```python
        &gt;&gt;&gt; pyboy.game_wrapper.shape
        (32, 32)
        ```
        &#34;&#34;&#34;
        self._set_dimensions(*game_area_section, game_area_follow_scxy)
        width, height = self.shape
        self._cached_game_area_tiles_raw = array(&#34;B&#34;, [0xFF] * (width * height * 4))
        self._cached_game_area_tiles = memoryview(self._cached_game_area_tiles_raw).cast(&#34;I&#34;, shape=(width, height))

        self.saved_state = io.BytesIO()

        self.tilemap_background = self.pyboy.tilemap_background
        self.tilemap_window = self.pyboy.tilemap_window

    def enabled(self):
        return self.cartridge_title is None or self.pyboy.cartridge_title == self.cartridge_title

    def post_tick(self):
        self._tile_cache_invalid = True
        self._sprite_cache_invalid = True

    def _set_timer_div(self, timer_div):
        if timer_div is None:
            self.mb.timer.DIV = random.getrandbits(8)
        else:
            self.mb.timer.DIV = timer_div &amp; 0xFF

    def start_game(self, timer_div=None):
        &#34;&#34;&#34;
        Call this function right after initializing PyBoy. This will navigate through menus to start the game at the
        first playable state.

        A value can be passed to set the timer&#39;s DIV register. Some games depend on it for randomization.

        The state of the emulator is saved, and using `reset_game`, you can get back to this point of the game
        instantly.

        Args:
            timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
        &#34;&#34;&#34;

        self.game_has_started = True
        self.saved_state.seek(0)
        self.pyboy.save_state(self.saved_state)
        self._set_timer_div(timer_div)

    def reset_game(self, timer_div=None):
        &#34;&#34;&#34;
        After calling `start_game`, you can call this method at any time to reset the game.

        Args:
            timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
        &#34;&#34;&#34;

        if self.game_has_started:
            self.saved_state.seek(0)
            self.pyboy.load_state(self.saved_state)
            self._set_timer_div(timer_div)
            self.post_tick()
        else:
            raise utils.PyBoyException(&#34;Tried to reset game, but it hasn&#39;t been started yet!&#34;)

    def game_over(self):
        &#34;&#34;&#34;
        After calling `start_game`, you can call this method at any time to know if the game is over.
        &#34;&#34;&#34;
        raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

    def _sprites_on_screen(self):
        if self._sprite_cache_invalid:
            self._cached_sprites_on_screen = []
            for s in range(SPRITES):
                sprite = self.pyboy.get_sprite(s)
                if sprite.on_screen:
                    self._cached_sprites_on_screen.append(sprite)
            self._sprite_cache_invalid = False
        return self._cached_sprites_on_screen

    def _game_area_tiles(self):
        if self._tile_cache_invalid:
            xx, yy, width, height = self.game_area_section
            scanline_parameters = self.pyboy.screen.tilemap_position_list

            if self.game_area_follow_scxy:
                self._cached_game_area_tiles = np.ndarray(shape=(height, width), dtype=np.uint32)
                for y in range(height):
                    SCX = scanline_parameters[(yy + y) * 8][0] // 8
                    SCY = scanline_parameters[(yy + y) * 8][1] // 8
                    for x in range(width):
                        _x = (xx + x + SCX) % 32
                        _y = (yy + y + SCY) % 32
                        if self.tilemap_use_background:
                            self._cached_game_area_tiles[y, x] = self.tilemap_background.tile_identifier(_x, _y)
                        else:
                            self._cached_game_area_tiles[y, x] = self.tilemap_window.tile_identifier(_x, _y)
            else:
                if self.tilemap_use_background:
                    self._cached_game_area_tiles = np.asarray(
                        self.tilemap_background[xx : xx + width, yy : yy + height], dtype=np.uint32
                    )
                else:
                    self._cached_game_area_tiles = np.asarray(
                        self.tilemap_window[xx : xx + width, yy : yy + height], dtype=np.uint32
                    )
            self._tile_cache_invalid = False
        return self._cached_game_area_tiles

    def use_background(self, value):
        self.tilemap_use_background = value

    def game_area(self):
        &#34;&#34;&#34;
        This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.

        Returns
        -------
        memoryview:
            Simplified 2-dimensional memoryview of the screen
        &#34;&#34;&#34;
        tiles_matrix = self.mapping[self._game_area_tiles()]
        sprites = self._sprites_on_screen()
        xx, yy, width, height = self.game_area_section
        for s in sprites:
            _x = (s.x // 8) - xx
            _y = (s.y // 8) - yy
            if 0 &lt;= _x &lt; width:
                # Adding offset to try to seperate sprites from tiles
                if 0 &lt;= _y &lt; height:
                    tiles_matrix[_y][_x] = self.mapping[s.tile_identifier] + self.sprite_offset
                if len(s.tiles) == 2 and 0 &lt;= _y + 1 &lt; height:  # Sprite has two tiles
                    tiles_matrix[_y + 1][_x] = self.mapping[s.tile_identifier + 1] + self.sprite_offset

        return tiles_matrix

    def game_area_mapping(self, mapping, sprite_offest):
        self.mapping = np.asarray(mapping, dtype=np.uint32)
        self.sprite_offset = sprite_offest

    def _set_dimensions(self, x, y, width, height, follow_scrolling=True):
        self.shape = (width, height)
        self.game_area_section = (x, y, width, height)
        self.game_area_follow_scxy = follow_scrolling

    def _sum_number_on_screen(self, x, y, length, blank_tile_identifier, tile_identifier_offset):
        number = 0
        for i, x in enumerate(self.tilemap_background[x : x + length, y]):
            if x != blank_tile_identifier:
                number += (x + tile_identifier_offset) * (10 ** (length - 1 - i))
        return number

    def __repr__(self):
        adjust = 4

        sprites = &#34;\n&#34;.join([str(s) for s in self._sprites_on_screen()])

        tiles_header = (
            &#34; &#34; * 4 + &#34;&#34;.join([f&#34;{i: &gt;4}&#34; for i in range(self.shape[0])]) + &#34;\n&#34; + &#34;_&#34; * (adjust * self.shape[0] + 4)
        )

        tiles = &#34;\n&#34;.join(
            [
                (f&#34;{i: &lt;3}|&#34; + &#34;&#34;.join([str(tile).rjust(adjust) for tile in line])).strip()
                for i, line in enumerate(self.game_area())
            ]
        )

        return &#34;Sprites on screen:\n&#34; + sprites + &#34;\n&#34; + &#34;Tiles on screen:\n&#34; + tiles_header + &#34;\n&#34; + tiles</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper"><code class="flex name class">
<span>class <span class="ident">PyBoyGameWrapper</span></span>
<span>(</span><span>*args, game_area_section=(0, 0, 32, 32), game_area_follow_scxy=False, **kwargs)</span>
</code></dt>
<dd>
<section class="desc"><p>This is the base-class for the game-wrappers. It provides some generic game-wrapping functionality, like <code>game_area</code>
, which shows both sprites and tiles on the screen as a simple matrix.</p></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class PyBoyGameWrapper(PyBoyPlugin):
    &#34;&#34;&#34;
    This is the base-class for the game-wrappers. It provides some generic game-wrapping functionality, like `game_area`
    , which shows both sprites and tiles on the screen as a simple matrix.
    &#34;&#34;&#34;

    cartridge_title = None

    mapping_one_to_one = np.arange(TILES_CGB, dtype=np.uint8)
    &#34;&#34;&#34;
    Example mapping of 1:1
    &#34;&#34;&#34;

    def __init__(self, *args, game_area_section=(0, 0, 32, 32), game_area_follow_scxy=False, **kwargs):
        super().__init__(*args, **kwargs)
        if not utils.cython_compiled:
            self.tilemap_background = self.pyboy.tilemap_background
            self.tilemap_window = self.pyboy.tilemap_window
        self.tilemap_use_background = True
        self.mapping = np.arange(TILES_CGB, dtype=np.uint32)
        self.sprite_offset = 0
        self.game_has_started = False
        self._tile_cache_invalid = True
        self._sprite_cache_invalid = True

        self.shape = None
        &#34;&#34;&#34;
        The shape of the game area. This can be modified with `pyboy.PyBoy.game_area_dimensions`.

        Example:
        ```python
        &gt;&gt;&gt; pyboy.game_wrapper.shape
        (32, 32)
        ```
        &#34;&#34;&#34;
        self._set_dimensions(*game_area_section, game_area_follow_scxy)
        width, height = self.shape
        self._cached_game_area_tiles_raw = array(&#34;B&#34;, [0xFF] * (width * height * 4))
        self._cached_game_area_tiles = memoryview(self._cached_game_area_tiles_raw).cast(&#34;I&#34;, shape=(width, height))

        self.saved_state = io.BytesIO()

        self.tilemap_background = self.pyboy.tilemap_background
        self.tilemap_window = self.pyboy.tilemap_window

    def enabled(self):
        return self.cartridge_title is None or self.pyboy.cartridge_title == self.cartridge_title

    def post_tick(self):
        self._tile_cache_invalid = True
        self._sprite_cache_invalid = True

    def _set_timer_div(self, timer_div):
        if timer_div is None:
            self.mb.timer.DIV = random.getrandbits(8)
        else:
            self.mb.timer.DIV = timer_div &amp; 0xFF

    def start_game(self, timer_div=None):
        &#34;&#34;&#34;
        Call this function right after initializing PyBoy. This will navigate through menus to start the game at the
        first playable state.

        A value can be passed to set the timer&#39;s DIV register. Some games depend on it for randomization.

        The state of the emulator is saved, and using `reset_game`, you can get back to this point of the game
        instantly.

        Args:
            timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
        &#34;&#34;&#34;

        self.game_has_started = True
        self.saved_state.seek(0)
        self.pyboy.save_state(self.saved_state)
        self._set_timer_div(timer_div)

    def reset_game(self, timer_div=None):
        &#34;&#34;&#34;
        After calling `start_game`, you can call this method at any time to reset the game.

        Args:
            timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
        &#34;&#34;&#34;

        if self.game_has_started:
            self.saved_state.seek(0)
            self.pyboy.load_state(self.saved_state)
            self._set_timer_div(timer_div)
            self.post_tick()
        else:
            raise utils.PyBoyException(&#34;Tried to reset game, but it hasn&#39;t been started yet!&#34;)

    def game_over(self):
        &#34;&#34;&#34;
        After calling `start_game`, you can call this method at any time to know if the game is over.
        &#34;&#34;&#34;
        raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)

    def _sprites_on_screen(self):
        if self._sprite_cache_invalid:
            self._cached_sprites_on_screen = []
            for s in range(SPRITES):
                sprite = self.pyboy.get_sprite(s)
                if sprite.on_screen:
                    self._cached_sprites_on_screen.append(sprite)
            self._sprite_cache_invalid = False
        return self._cached_sprites_on_screen

    def _game_area_tiles(self):
        if self._tile_cache_invalid:
            xx, yy, width, height = self.game_area_section
            scanline_parameters = self.pyboy.screen.tilemap_position_list

            if self.game_area_follow_scxy:
                self._cached_game_area_tiles = np.ndarray(shape=(height, width), dtype=np.uint32)
                for y in range(height):
                    SCX = scanline_parameters[(yy + y) * 8][0] // 8
                    SCY = scanline_parameters[(yy + y) * 8][1] // 8
                    for x in range(width):
                        _x = (xx + x + SCX) % 32
                        _y = (yy + y + SCY) % 32
                        if self.tilemap_use_background:
                            self._cached_game_area_tiles[y, x] = self.tilemap_background.tile_identifier(_x, _y)
                        else:
                            self._cached_game_area_tiles[y, x] = self.tilemap_window.tile_identifier(_x, _y)
            else:
                if self.tilemap_use_background:
                    self._cached_game_area_tiles = np.asarray(
                        self.tilemap_background[xx : xx + width, yy : yy + height], dtype=np.uint32
                    )
                else:
                    self._cached_game_area_tiles = np.asarray(
                        self.tilemap_window[xx : xx + width, yy : yy + height], dtype=np.uint32
                    )
            self._tile_cache_invalid = False
        return self._cached_game_area_tiles

    def use_background(self, value):
        self.tilemap_use_background = value

    def game_area(self):
        &#34;&#34;&#34;
        This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.

        Returns
        -------
        memoryview:
            Simplified 2-dimensional memoryview of the screen
        &#34;&#34;&#34;
        tiles_matrix = self.mapping[self._game_area_tiles()]
        sprites = self._sprites_on_screen()
        xx, yy, width, height = self.game_area_section
        for s in sprites:
            _x = (s.x // 8) - xx
            _y = (s.y // 8) - yy
            if 0 &lt;= _x &lt; width:
                # Adding offset to try to seperate sprites from tiles
                if 0 &lt;= _y &lt; height:
                    tiles_matrix[_y][_x] = self.mapping[s.tile_identifier] + self.sprite_offset
                if len(s.tiles) == 2 and 0 &lt;= _y + 1 &lt; height:  # Sprite has two tiles
                    tiles_matrix[_y + 1][_x] = self.mapping[s.tile_identifier + 1] + self.sprite_offset

        return tiles_matrix

    def game_area_mapping(self, mapping, sprite_offest):
        self.mapping = np.asarray(mapping, dtype=np.uint32)
        self.sprite_offset = sprite_offest

    def _set_dimensions(self, x, y, width, height, follow_scrolling=True):
        self.shape = (width, height)
        self.game_area_section = (x, y, width, height)
        self.game_area_follow_scxy = follow_scrolling

    def _sum_number_on_screen(self, x, y, length, blank_tile_identifier, tile_identifier_offset):
        number = 0
        for i, x in enumerate(self.tilemap_background[x : x + length, y]):
            if x != blank_tile_identifier:
                number += (x + tile_identifier_offset) * (10 ** (length - 1 - i))
        return number

    def __repr__(self):
        adjust = 4

        sprites = &#34;\n&#34;.join([str(s) for s in self._sprites_on_screen()])

        tiles_header = (
            &#34; &#34; * 4 + &#34;&#34;.join([f&#34;{i: &gt;4}&#34; for i in range(self.shape[0])]) + &#34;\n&#34; + &#34;_&#34; * (adjust * self.shape[0] + 4)
        )

        tiles = &#34;\n&#34;.join(
            [
                (f&#34;{i: &lt;3}|&#34; + &#34;&#34;.join([str(tile).rjust(adjust) for tile in line])).strip()
                for i, line in enumerate(self.game_area())
            ]
        )

        return &#34;Sprites on screen:\n&#34; + sprites + &#34;\n&#34; + &#34;Tiles on screen:\n&#34; + tiles_header + &#34;\n&#34; + tiles</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li>pyboy.plugins.base_plugin.PyBoyPlugin</li>
</ul>
<h3>Subclasses</h3>
<ul class="hlist">
<li><a title="pyboy.plugins.game_wrapper_kirby_dream_land.GameWrapperKirbyDreamLand" href="game_wrapper_kirby_dream_land.html#pyboy.plugins.game_wrapper_kirby_dream_land.GameWrapperKirbyDreamLand">GameWrapperKirbyDreamLand</a></li>
<li><a title="pyboy.plugins.game_wrapper_pokemon_gen1.GameWrapperPokemonGen1" href="game_wrapper_pokemon_gen1.html#pyboy.plugins.game_wrapper_pokemon_gen1.GameWrapperPokemonGen1">GameWrapperPokemonGen1</a></li>
<li><a title="pyboy.plugins.game_wrapper_pokemon_pinball.GameWrapperPokemonPinball" href="game_wrapper_pokemon_pinball.html#pyboy.plugins.game_wrapper_pokemon_pinball.GameWrapperPokemonPinball">GameWrapperPokemonPinball</a></li>
<li><a title="pyboy.plugins.game_wrapper_super_mario_land.GameWrapperSuperMarioLand" href="game_wrapper_super_mario_land.html#pyboy.plugins.game_wrapper_super_mario_land.GameWrapperSuperMarioLand">GameWrapperSuperMarioLand</a></li>
<li><a title="pyboy.plugins.game_wrapper_tetris.GameWrapperTetris" href="game_wrapper_tetris.html#pyboy.plugins.game_wrapper_tetris.GameWrapperTetris">GameWrapperTetris</a></li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.cartridge_title"><code class="name">var <span class="ident">cartridge_title</span></code></dt>
<dd>
<section class="desc"></section>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.mapping_one_to_one"><code class="name">var <span class="ident">mapping_one_to_one</span></code></dt>
<dd>
<section class="desc"><p>Example mapping of 1:1</p></section>
</dd>
</dl>
<h3>Instance variables</h3>
<dl>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.shape"><code class="name">var <span class="ident">shape</span></code></dt>
<dd>
<section class="desc"><p>The shape of the game area. This can be modified with <code><a title="pyboy.PyBoy.game_area_dimensions" href="../index.html#pyboy.PyBoy.game_area_dimensions">PyBoy.game_area_dimensions()</a></code>.</p>
<p>Example:</p>
<pre><code class="language-python">&gt;&gt;&gt; pyboy.game_wrapper.shape
(32, 32)
</code></pre></section>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.start_game"><code class="name flex">
<span>def <span class="ident">start_game</span></span>(<span>self, timer_div=None)</span>
</code></dt>
<dd>
<section class="desc"><p>Call this function right after initializing PyBoy. This will navigate through menus to start the game at the
first playable state.</p>
<p>A value can be passed to set the timer's DIV register. Some games depend on it for randomization.</p>
<p>The state of the emulator is saved, and using <code>reset_game</code>, you can get back to this point of the game
instantly.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>timer_div</code></strong> :&ensp;<code>int</code></dt>
<dd>Replace timer's DIV register with this value. Use <code>None</code> to randomize.</dd>
</dl></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def start_game(self, timer_div=None):
    &#34;&#34;&#34;
    Call this function right after initializing PyBoy. This will navigate through menus to start the game at the
    first playable state.

    A value can be passed to set the timer&#39;s DIV register. Some games depend on it for randomization.

    The state of the emulator is saved, and using `reset_game`, you can get back to this point of the game
    instantly.

    Args:
        timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
    &#34;&#34;&#34;

    self.game_has_started = True
    self.saved_state.seek(0)
    self.pyboy.save_state(self.saved_state)
    self._set_timer_div(timer_div)</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.reset_game"><code class="name flex">
<span>def <span class="ident">reset_game</span></span>(<span>self, timer_div=None)</span>
</code></dt>
<dd>
<section class="desc"><p>After calling <code>start_game</code>, you can call this method at any time to reset the game.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>timer_div</code></strong> :&ensp;<code>int</code></dt>
<dd>Replace timer's DIV register with this value. Use <code>None</code> to randomize.</dd>
</dl></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def reset_game(self, timer_div=None):
    &#34;&#34;&#34;
    After calling `start_game`, you can call this method at any time to reset the game.

    Args:
        timer_div (int): Replace timer&#39;s DIV register with this value. Use `None` to randomize.
    &#34;&#34;&#34;

    if self.game_has_started:
        self.saved_state.seek(0)
        self.pyboy.load_state(self.saved_state)
        self._set_timer_div(timer_div)
        self.post_tick()
    else:
        raise utils.PyBoyException(&#34;Tried to reset game, but it hasn&#39;t been started yet!&#34;)</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_over"><code class="name flex">
<span>def <span class="ident">game_over</span></span>(<span>self)</span>
</code></dt>
<dd>
<section class="desc"><p>After calling <code>start_game</code>, you can call this method at any time to know if the game is over.</p></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def game_over(self):
    &#34;&#34;&#34;
    After calling `start_game`, you can call this method at any time to know if the game is over.
    &#34;&#34;&#34;
    raise NotImplementedError(&#34;game_over not implemented in game wrapper&#34;)</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background"><code class="name flex">
<span>def <span class="ident">use_background</span></span>(<span>self, value)</span>
</code></dt>
<dd>
<section class="desc"></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def use_background(self, value):
    self.tilemap_use_background = value</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area"><code class="name flex">
<span>def <span class="ident">game_area</span></span>(<span>self)</span>
</code></dt>
<dd>
<section class="desc"><p>This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.</p>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>memoryview:</code></dt>
<dd>Simplified 2-dimensional memoryview of the screen</dd>
</dl></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def game_area(self):
    &#34;&#34;&#34;
    This method returns a cut-out of the screen as a simplified matrix for use in machine learning applications.

    Returns
    -------
    memoryview:
        Simplified 2-dimensional memoryview of the screen
    &#34;&#34;&#34;
    tiles_matrix = self.mapping[self._game_area_tiles()]
    sprites = self._sprites_on_screen()
    xx, yy, width, height = self.game_area_section
    for s in sprites:
        _x = (s.x // 8) - xx
        _y = (s.y // 8) - yy
        if 0 &lt;= _x &lt; width:
            # Adding offset to try to seperate sprites from tiles
            if 0 &lt;= _y &lt; height:
                tiles_matrix[_y][_x] = self.mapping[s.tile_identifier] + self.sprite_offset
            if len(s.tiles) == 2 and 0 &lt;= _y + 1 &lt; height:  # Sprite has two tiles
                tiles_matrix[_y + 1][_x] = self.mapping[s.tile_identifier + 1] + self.sprite_offset

    return tiles_matrix</code></pre>
</details>
</dd>
<dt id="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area_mapping"><code class="name flex">
<span>def <span class="ident">game_area_mapping</span></span>(<span>self, mapping, sprite_offest)</span>
</code></dt>
<dd>
<section class="desc"></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def game_area_mapping(self, mapping, sprite_offest):
    self.mapping = np.asarray(mapping, dtype=np.uint32)
    self.sprite_offset = sprite_offest</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="pyboy.plugins" href="index.html">pyboy.plugins</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper">PyBoyGameWrapper</a></code></h4>
<ul class="two-column">
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.start_game" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.start_game">start_game</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.reset_game" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.reset_game">reset_game</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_over" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.game_over">game_over</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.use_background">use_background</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area">game_area</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area_mapping" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.game_area_mapping">game_area_mapping</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.shape" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.shape">shape</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.cartridge_title" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.cartridge_title">cartridge_title</a></code></li>
<li><code><a title="pyboy.plugins.base_plugin.PyBoyGameWrapper.mapping_one_to_one" href="#pyboy.plugins.base_plugin.PyBoyGameWrapper.mapping_one_to_one">mapping_one_to_one</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.11.5</a>.</p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
</body>
</html>
